package com.shadowtorcher.soulknife.util;/*
 * Copyright (C)  li, Shadow Torcher project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Iterator;
import java.util.Set;

public class Untils {
    /**
     * 问号字符串生成器
     *
     * @param number 问号的数量
     * @return 问号间以逗号间隔，最后一个问号后面没有逗号
     */
    public static String QuestionGenerator(int number) {
        StringBuilder stringBuilder = new StringBuilder();
        int i;
        for (i = 1; i < number; i++) {
            stringBuilder.append("?,");
        }
        if (i == number)
            stringBuilder.append("?");
        return stringBuilder.toString();
    }

    /**
     * 字符串连接器
     *
     * @param set 字符串集合
     * @return 字符串间以逗号间隔，最后一个字符串后面没有逗号
     */
    public static String StringGenerator(Set<String> set) {
        Iterator<String> data = set.iterator();
        StringBuilder stringBuilder = new StringBuilder();
        int i;
        for (i = 1; i < set.size(); i++) {
            stringBuilder.append(data.next()).append(",");
        }
        if (i == set.size())
            stringBuilder.append(data.next());
        return stringBuilder.toString();
    }
}
